Developer Documentation

QuickTime 4 API Documentation

Inside Macintosh: Memory

Previous | Chapter Top | Chapter Contents | Next |

Assessing Memory Conditions

The Memory Manager provides routines to test how much memory is available. To determine the total amount of free space in the current heap zone or the size of the maximum block that could be obtained after a purge of the heap, call the PurgeSpace function.

To find out whether a Memory Manager operation finished successfully, use the MemError function.

PurgeSpace

Use the PurgeSpace procedure to determine the total amount of free memory and the size of the largest allocatable block after a purge of the heap.

PROCEDURE PurgeSpace (VAR total: LongInt; VAR contig: LongInt);
total
On exit, the total amount of free memory in the current heap zone if it were purged.
contig
On exit, the size of the largest contiguous block of free memory in the current heap zone if it were purged.

DESCRIPTION

The PurgeSpace procedure returns, in the total parameter, the total amount of space (in bytes) that could be obtained after a general purge of the current heap zone; this amount includes space that is already free. In the contig parameter, PurgeSpace returns the size of the largest allocatable block in the current heap zone that could be obtained after a purge of the zone.

The PurgeSpace procedure does not actually purge the current heap zone.

ASSEMBLY-LANGUAGE INFORMATION

The registers on exit for PurgeSpace are

Registers on exit

A0

Maximum number of contiguous bytes after purge

D0

Total free memory after purge

RESULT CODES

noErr

0

No error

MemError

To find out whether your application's last direct call to a Memory Manager routine executed successfully, use the MemError function.

FUNCTION MemError: OSErr;

DESCRIPTION

The MemError function returns the result code produced by the last Memory Manager routine your application called directly.

This function is useful during application debugging. You might also use the function as one part of a memory-management scheme to identify instances in which the Memory Manager rejects overly large memory requests by returning the error code memFullErr .

Do not rely on the MemError function as the only component of a memory-management scheme. For example, suppose you call NewHandle or NewPtr and receive the result code noErr , indicating that the Memory Manager was able to allocate sufficient memory. In this case, you have no guarantee that the allocation did not deplete your application's memory reserves to levels so low that simple operations might cause your application to crash. Instead of relying on MemError , check before making a memory request that there is enough memory both to fulfill the request and to support essential operations.

ASSEMBLY-LANGUAGE INFORMATION

Because most Memory Manager routines return a result code in register D0, you do not ordinarily need to call the MemError function if you program in assembly language. See the description of an individual routine to find out whether it returns a result code in register D0. If not, you can examine the global variable MemErr . When MemError returns, register D0 contains the result code.

Registers on exit

D0

Result code

RESULT CODES

noErr

0

No error

paramErr

-50

Error in parameter list

memROZErr

-99

Operation on a read-only zone

memFullErr

-108

Not enough memory

nilHandleErr

-109

NIL master pointer

memWZErr

-111

Attempt to operate on a free block

memPurErr

-112

Attempt to purge a locked block

memBCErr

-115

Block check failed

memLockedErr

-117

Block is locked


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next